-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add otel support #25862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: add otel support #25862
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- The
Config.Protocolcomment says gRPC is the default, butInitcurrently usescfg.Protocoldirectly and will treat an empty string as an error; either defaultprotocol := cfg.Protocol; if protocol == "" { protocol = "grpc" }or update the comment/config to reflect that it’s required. - The
Config.Headersfield is defined but never used when constructing the OTLP exporters; if you intend to support custom headers (for auth, tenancy, etc.), plumb these intootlptracegrpc.New/otlptracehttp.New, or remove the field for now to avoid confusion.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `Config.Protocol` comment says gRPC is the default, but `Init` currently uses `cfg.Protocol` directly and will treat an empty string as an error; either default `protocol := cfg.Protocol; if protocol == "" { protocol = "grpc" }` or update the comment/config to reflect that it’s required.
- The `Config.Headers` field is defined but never used when constructing the OTLP exporters; if you intend to support custom headers (for auth, tenancy, etc.), plumb these into `otlptracegrpc.New` / `otlptracehttp.New`, or remove the field for now to avoid confusion.
## Individual Comments
### Comment 1
<location> `util/otel/otel.go:44-45` </location>
<code_context>
+ var exporter sdktrace.SpanExporter
+ var err error
+
+ // Default to grpc if protocol not specified
+ protocol := cfg.Protocol
+ switch protocol {
+ case "grpc":
</code_context>
<issue_to_address>
**issue (bug_risk):** The protocol comment and implementation diverge; empty protocol currently fails instead of defaulting to gRPC.
Because `protocol := cfg.Protocol` goes straight into the `switch`, an empty string will fall into `default` and return an error, effectively making `Protocol` mandatory whenever otel is enabled. To match the comment, initialize a default first, e.g.:
```go
actionProtocol := cfg.Protocol
if actionProtocol == "" {
actionProtocol = "grpc"
}
```
Also consider using the resolved value (e.g., `actionProtocol`) in the final log line instead of the raw config field.
</issue_to_address>
### Comment 2
<location> `util/otel/otel.go:28` </location>
<code_context>
+ Endpoint string `json:"endpoint"`
+ Protocol string `json:"protocol"` // "grpc" or "http"
+ Insecure bool `json:"insecure"`
+ Headers map[string]string
+}
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Configured OTLP headers are accepted but never applied to the exporters.
The `Headers` field is exposed on `Config` but never used when creating the gRPC/HTTP exporters. If it’s meant for auth/metadata, it should be passed into the exporter options (e.g., `otlptracegrpc.WithHeaders(cfg.Headers)` / `otlptracehttp.WithHeaders(cfg.Headers)`). Otherwise, consider removing it from `Config` to avoid a misleading, no-op setting.
Suggested implementation:
```golang
// Config holds OpenTelemetry configuration
type Config struct {
Enabled bool `json:"enabled"`
Endpoint string `json:"endpoint"`
Protocol string `json:"protocol"` // "grpc" or "http"
Insecure bool `json:"insecure"`
Headers map[string]string `json:"headers,omitempty"`
```
```golang
opts := []otlptracegrpc.Option{
otlptracegrpc.WithEndpoint(cfg.Endpoint),
}
if len(cfg.Headers) > 0 {
opts = append(opts, otlptracegrpc.WithHeaders(cfg.Headers))
}
```
```golang
opts := []otlptracehttp.Option{
otlptracehttp.WithEndpoint(cfg.Endpoint),
}
if len(cfg.Headers) > 0 {
opts = append(opts, otlptracehttp.WithHeaders(cfg.Headers))
}
```
If the option slices for gRPC/HTTP exporters are named differently or constructed inline (e.g., directly in `otlptracegrpc.New` / `otlptracehttp.New` calls), you’ll need to adapt the `SEARCH` patterns accordingly and still ensure that `otlptracegrpc.WithHeaders(cfg.Headers)` and `otlptracehttp.WithHeaders(cfg.Headers)` are appended to the respective option lists whenever `len(cfg.Headers) > 0`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
4686903 to
e42339d
Compare
e42339d to
f5fe145
Compare
f5fe145 to
065a0ed
Compare
|
+1% binary size and quite some additional dependencies. Apart from being an interesting technology- I'd like to better understand how one would actually utilize this? |
Yeah there are more dependencies which can increase the size of the binary, but I think its worth it. You can read this for reference. Tracing is particularly helpful when debugging complex distributed systems, but I find it useful in every application. They are a nice addition to the logs - you can visualize and debug complex workflows with a tracing backend + visualization engine. You dont have just rely on understanding the code to see how the system behaves. Plus, since evcc interacts with many subsystems - correlating events across components (chargers, meters, vehicles, MQTT/HTTP/Modbus, possibly external APIs). OTel spans/traces could help show timing and causality: e.g. “when meter reading X arrived → charger throttled → mqtt message published → UI updated”. That’s harder to reconstruct purely from log + time-series data. |
Initial OpenTelemetry support (config, init, http API tracing).
Useful for complex scenario debugging (instead of relying solely on logs).
Ran it with the following compose:
This section should also be added to
evcc.yaml